<?php
namespace App\Models;

use DB;
use Illuminate\Database\Eloquent\Model;
class UserFollowM extends Model
{
    protected $table='lee_user_follow';
    static public $STable='lee_user_follow';
    protected $fillable = ['userid', 'followid'];
    
    /**
     * 添加 关注记录
     * @param array $inputData
     * ['userid'=>1,'followid'=>11]
     */
    public static  function newFollowItem(array $inputData){
        $userInst=new UserFollowM($inputData);
        $userInst->save();
    }
    
    /**
     * 依据用户id 返回其关注列表
     * @param bigint $userid 用户id
     */
    public static function getFollows($userid){
        $followTName=self::$STable;
        $userTName=UserM::$STable;
        $sql="select 
        us.id as userid, us.name as username,us.avatar as avatar,
        us.height as height,us.weight as weight,
        us.address as address,us.bra as bra,us.underbustgirth as underbustgirth,
        us.fansnum as funsnum, us.avatar as avatar,us.sign as sign 
        from $userTName as us
    
        where id in (select followid from $followTName where userid =$userid)";
        return DB::select($sql);
    }
    
    /**
     * 删除 关注记录
     * @param array $inputData,输入数据
     *
     * ['userid'=>1,'followid'=>11]
     */
    public static  function deltFollowItem(array $inputData){
    
        self::where($inputData)->delete();
    }
}

?>